package com.hmall.item.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ItemQueueConfig {
    /**
     * 定义交换机
     * @return
     */
    @Bean
    public DirectExchange exchange(){
        return ExchangeBuilder.directExchange("item.direct").build();
    }
    /**
     * 定义新增的消息队列
     * @return
     */
    @Bean
    public Queue insert(){
       return QueueBuilder.durable("item.insert.queue").build();
    }

    /**
     * 定义删除的消息队列
     * @return
     */
    @Bean
    public Queue delete(){
        return QueueBuilder.durable("item.delete.queue").build();
    }

    /**
     * 定义路由和新增队列的绑定
     * @return
     */
    @Bean
    public Binding bindingInsert(){
        return BindingBuilder.bind(insert()).to(exchange()).with("item.insert");
    }

    /**
     * 定义路由和删除队列的绑定
     * @return
     */
    @Bean
    public Binding bindingDelete(){
        return BindingBuilder.bind(delete()).to(exchange()).with("item.delete");
    }
}
